package com.mallcai.bigdata.ladon.service.system.impl;

import com.mallcai.bigdata.ladon.service.system.IEnvService;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.Arrays;


/**
 * @author feixy
 * @version 1.0
 * @date 2019-08-27 10:26
 */
@Service
public class EnvService implements IEnvService, EnvironmentAware {

    private Environment environment;

    @Override
    public boolean isProduct() {
        return isActive("product_vpc");
    }

    @Override
    public boolean isAlpha() {
        return isActive("alpha");
    }

    @Override
    public boolean isDev() {
        return isActive("dev");
    }

    @Override
    public String[] getActiveProfiles(){
        return environment.getActiveProfiles();
    }

    @Override
    public boolean isActive(String profile) {
        return Arrays.stream(getActiveProfiles()).anyMatch(item-> item.equalsIgnoreCase(profile));
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
